
/**
 * Created by jinghua on 2020/8/18.
 */
let arrdata = [],jsonOverlayears = [],selectRoadId='';
roadSectionId = '';
$(document).ready(function() {
	var curDate = new Date().Format("yyyy-MM")
	$('#budgetDate').val(curDate);
	$('#budgetroadrepairedDate').val(curDate);
	/*预结算分析*/
	var roadResObj, repairedResObj;
	/*左侧导航*/
	$('.way1').on('click', function() {
		setYjstatus();
		if(!$('#bottomLay').hasClass('bottomHide')){
			$('#bottomLay').addClass('bottomHide');
		}
		if(!$('.way2').parent().hasClass('nav-hide') || !$('.way3').parent().hasClass('nav-hide') || !$('.way4').parent().hasClass('menu-hide') || !$('.way5').parent().hasClass('menu-hide') ) {
			
			$('.way1').parent().removeClass("nav-hide");
			$('.way2').parent().addClass("nav-hide");
			$('.way3').parent().addClass("nav-hide");
			$('.way5').parent().addClass("menu-hide");
			$('.way4').parent().addClass("menu-hide");
		}else{
			if (!$('.way1').parent().hasClass('nav-hide')) {
				console.log('zheng')
				$('.way1').parent().addClass("nav-hide");
				$('.left-list ul li a').hide()
			} else {
				$('.way1').parent().removeClass("nav-hide");
				$('.left-list ul li a').show()
			}
		}
		
	});
	$('.way2').on('click', function() {
		setYjstatus();
		if(!$('#bottomLay').hasClass('bottomHide')){
			$('#bottomLay').addClass('bottomHide');
		}
		if(!$('.way1').parent().hasClass('nav-hide') || !$('.way3').parent().hasClass('nav-hide') || !$('.way4').parent().hasClass('menu-hide') || !$('.way5').parent().hasClass('menu-hide') ) {
			console.log('2')
			$('.way2').parent().removeClass("nav-hide");
			$('.way1').parent().addClass("nav-hide");
			$('.way3').parent().addClass("nav-hide");
			$('.way5').parent().addClass("menu-hide");
			$('.way4').parent().addClass("menu-hide");
		}else{
			if (!$('.way2').parent().hasClass('nav-hide')) {
				console.log('zheng2')
				$('.way2').parent().addClass("nav-hide");
				$('.left-list ul li a').hide()
			} else {
				
				$('.way2').parent().removeClass("nav-hide");
				$('.left-list ul li a').show()
			}
		}
	});
	$('.way3').on('click', function() {
		setYjstatus();
		if(!$('#bottomLay').hasClass('bottomHide')){
			$('#bottomLay').addClass('bottomHide');
		}
		if(!$('.way1').parent().hasClass('nav-hide') || !$('.way2').parent().hasClass('nav-hide') || !$('.way4').parent().hasClass('menu-hide') || !$('.way5').parent().hasClass('menu-hide')) {
			console.log('2')
			$('.way3').parent().removeClass("nav-hide");
			$('.way1').parent().addClass("nav-hide");
			$('.way2').parent().addClass("nav-hide");
			$('.way5').parent().addClass("menu-hide");
			$('.way4').parent().addClass("menu-hide");
		}else{
			console.log('dianji')
			if (!$('.way3').parent().hasClass('nav-hide')) {
				console.log('zheng2')
				$('.way3').parent().addClass("nav-hide");
				$('.left-list ul li a').hide()
			} else {
				console.log('jia2')
				$('.way3').parent().removeClass("nav-hide");
				$('.left-list ul li a').show()
			}
		}
	});
	$('.way4').on('click', function() {
		setYjstatus();
		if(!$('#bottomLay').hasClass('bottomHide')){
			$('#bottomLay').addClass('bottomHide');
		}
		if(!$('.way1').parent().hasClass('nav-hide') || !$('.way2').parent().hasClass('nav-hide') || !$('.way3').parent().hasClass('nav-hide')|| !$('.way5').parent().hasClass('menu-hide')) {
			console.log('2')
			$('.way4').parent().removeClass("menu-hide");
			$('.way1').parent().addClass("nav-hide");
			$('.way2').parent().addClass("nav-hide");
			$('.way3').parent().addClass("nav-hide");
			$('.way5').parent().addClass("menu-hide");
		}else{
			console.log('dianji')
			if (!$('.way4').parent().hasClass('menu-hide')) {
				console.log('zheng2')
				$('.way4').parent().addClass("menu-hide");
				$('.left-list ul li a').hide()
			} else {
				console.log('jia2')
				$('.way4').parent().removeClass("menu-hide");
				$('.left-list ul li a').show()
			}
		}
	});
	$('.way5').on('click', function() {
		setYjstatus();
		if(!$('#bottomLay').hasClass('bottomHide')){
			$('#bottomLay').addClass('bottomHide');
		}
		if(!$('.way1').parent().hasClass('nav-hide') || !$('.way2').parent().hasClass('nav-hide') || !$('.way3').parent().hasClass('nav-hide')|| !$('.way4').parent().hasClass('menu-hide') ) {
			console.log('2')
			$('.way5').parent().removeClass("menu-hide");
			$('.way1').parent().addClass("nav-hide");
			$('.way2').parent().addClass("nav-hide");
			$('.way3').parent().addClass("nav-hide");
			$('.way4').parent().addClass("menu-hide");
		}else{
			console.log('dianji')
			if (!$('.way5').parent().hasClass('menu-hide')) {
				console.log('zheng2')
				$('.way5').parent().addClass("menu-hide");
				$('.left-list ul li a').hide()
			} else {
				console.log('jia2')
				$('.way5').parent().removeClass("menu-hide");
				$('.left-list ul li a').show()
			}
		}
	});
	
	// $('#rightNav').on('click', 'span', function() {
	// 	if (!$(this).parent().hasClass('menu-hide')) {
	// 		$(this).parent().addClass("menu-hide");
	// 	} else {
	// 		$(this).parent().removeClass("menu-hide");
	// 	}
	// });
	$(".viod").click(function() {
		$(".yad").fadeIn();
	});
	$("#clod").click(function() {
		$(".yad").slideToggle();
	});
	$(".left-list ul li a").click(function() {
		$(this).addClass("curr").siblings("a").removeClass("curr");
	});
	$(".show-time a").click(function() {
		$(this).addClass("curr").siblings("a").removeClass("curr");
	});
	$(".gis").click(function() {
		$("#leftNav, #rightNav").fadeIn().siblings(".bim-whole").fadeOut();
		//window.location.href = 'canvas.html';
		$(".curr").fadeOut();
		$(".gis").fadeIn();

	});
	$(".bim").click(function() {
		window.location.href = './bigscreen/bim_example/index.html';
		$(".curr").fadeOut();
		$(".bim").fadeIn();
		// $("#leftNav, #rightNav").fadeOut().siblings(".bim-whole").fadeIn();
	});

	$(".homePage").click(function() {

		// $("#leftNav, #rightNav").fadeOut().siblings(".bim-whole").fadeIn();
	});
	/**左侧导航**/
	/*底部导航*/
	$('#footerNav').on('click', 'a', function() {
		setYjstatus();
		if ($(this).hasClass('curr')) {
			$('#bottomLay').addClass('bottomHide');
			$(this).removeClass('curr');
			return;
		}
		$('#leftNav>.nav').each(function(){
			if(!$(this).hasClass('nav-hide')){
				$(this).addClass('nav-hide');
			}
		});
		$('#rightNav>.menu').each(function(){
			if(!$(this).hasClass('menu-hide')){
				$(this).addClass('menu-hide');
			}
		});
		$(this).addClass("curr").siblings("a").removeClass("curr");
		var type = $(this).data('type');
		/*
		 * type: 01:资产分析 02:病害分析 03:预结算分析 04:监测数据 05:应急分析
		 * */
		$('.bottom-lay-cont').hide();
		var startTime = JSON.parse(localStorage.getItem("startTime"))
		var endTime = JSON.parse(localStorage.getItem("endTime"))
		console.log(startTime)
		console.log(endTime)
		// let jsonDate = facilityMaintenanceObj.setDate(startTime, endTime);
		switch (type) {
			case '01':
				$('#bottomLay').removeClass('bottomHide');
				$('#content1').show();
				$.get(baseUrl + 'maintainjudge' + "/main/assetanalysis/queryroadstatistics?",{startTime:startTime,endTime:endTime}, function(result) {
					var resObj = JSON.parse(result);
					//道路等級統計
					var dataList = [{
						name: 'A级',
						value: 0
					}, {
						name: 'B级',
						value: 0
					}, {
						name: 'C级',
						value: 0
					}, {
						name: 'D级',
						value: 0
					}];
					for (var i = 0; i < resObj.roadGradeList.length; i++) {
						var item = resObj.roadGradeList[i];
						for (var j = 0; j < dataList.length; j++) {
							var dataItem = dataList[j];
							if (dataItem.name.indexOf(item.name) != -1) {
								dataItem.value = item.count;
								break;
							}
						}
					}
					var chartDataTemp = {
						title: '道路等级统计',
						data: dataList
					};
					createPieChart(chartDataTemp, $('#chart3')[0]);

					//养护状况统计
					var yhDataList = [{
						name: '不合格',
						value: 0
					}, {
						name: '合格',
						value: 0
					}, {
						name: '良好',
						value: 0
					}, {
						name: '优秀',
						value: 0
					}];
					for (var i = 0; i < resObj.maintainStatusList.length; i++) {
						var item = resObj.maintainStatusList[i];
						for (var j = 0; j < yhDataList.length; j++) {
							var dataItem = yhDataList[j];
							if (item.name == dataItem.name) {
								dataItem.value = item.count;
								break;
							}
						}
					}
					var yhChartDataTemp = {
						title: '养护状况统计',
						data: yhDataList
					};
					createPieChart(yhChartDataTemp, $('#chart4')[0]);

					//保养建议
					var byDataList = [{
						name: '完好',
						value: 0
					}, {
						name: '小修',
						value: 0
					}, {
						name: '中修',
						value: 0
					}, {
						name: '大修',
						value: 0
					}];
					for (var i = 0; i < resObj.sugList.length; i++) {
						var item = resObj.sugList[i];
						for (var j = 0; j < byDataList.length; j++) {
							var dataItem = byDataList[j];
							if (item.name == dataItem.name) {
								dataItem.value = item.count;
								break;
							}
						}
					}
					var byChartDataTemp = {
						title: '保养建议',
						data: byDataList
					};
					createPieChart(byChartDataTemp, $('#chart5')[0]);
				});

				/* 道路等级统计 chart3*/
				// createPieChart(chartData3, $('#chart3')[0]);
				/* 养护状况统计 chart4*/
				// createPieChart(chartData4, $('#chart4')[0]);
				/* 养护状况统计 chart5*/
				// createPieChart(chartData5, $('#chart5')[0]);
				break;
			case '02':
				$('#bottomLay').removeClass('bottomHide');
				$('#content2').show();
				// createLineChart(chartData8, $('#chart6')[0]);
				$("#tabWrap").children("span").get(0).click();
				break;
			case '03':
				$('#bottomLay').removeClass('bottomHide');
				$('#content3').show();
				// createChart1(chartData1, $('#chart7')[0]);
				// createChart2(chartData2, $('#chart8')[0]);
				$("#tabWrap1").children("span").get(0).click();
				break;
			case '04':
				//获取检测数据
				var url = baseUrl + 'iotmanager' + '/main/checkdata/getcheckdata';
				$('#bottomLay').removeClass('bottomHide');
				$('#content4').show();
				$.get(url, {startTime:startTime,endTime:endTime},function(result) {
					var resObj = JSON.parse(result);

					//检测数据-桥梁
					$('#bridgeNormal').text(resObj.bridgeNormal);
					$('#bridgeWarning').text(resObj.bridgeWarning);
					$('#bridgeOffLine').text(resObj.bridgeOffLine);
					//检测数据-隧道
					$('#tunnelNormal').text(resObj.tunnelNormal);
					$('#tunnelWarning').text(resObj.tunnelWarning);
					$('#tunnelOffLine').text(resObj.tunnelOffLine);

					//监测数据-井盖
					$('#roadNormal').text(resObj.wellCoverNormal);
					$('#roadWarning').text(resObj.wellCoverWarning);
					$('#roadOffLine').text(resObj.wellCoverOffLine);

					console.log(resObj.roadIncludeAssetList);
					//监测数据-附属设施
					if(resObj.roadIncludeAssetList && resObj.roadIncludeAssetList.length>0){
						let firstObj = {};
						$("#jcFsssSelect option:not(:first)").remove();
						var _op = "";
						$.each(resObj.roadIncludeAssetList,function(index,item){
							if(index == 0){
								firstObj = item;
							}
							_op += "<option dcount='"+ item.count +"' dwarning='"+ item.warning +"' doffline='"+ item.offline +"' value='" + item.fname + "'>" + item.fname + "</option>"
						});
						$("#jcFsssSelect").append(_op);
						layuiSelectRender();
						$('#manholeNormal').text(firstObj.count);
						$('#manholeWarning').text(firstObj.warning);
						$('#manholeOffLine').text(firstObj.offline);
					}else{
						$('#manholeNormal').text('0');
						$('#manholeWarning').text('0');
						$('#manholeOffLine').text('0');
					}
				});
				break;
			case '05':
				$('#bottomLay').removeClass('bottomHide');
				$('#content5').show();
				//createChart12();
				bindSelect();
				break;
		}
	});
	/*病害分析 tab 页签*/
	$('#tabWrap').on('click', 'span', function() {
		$(this).addClass("curr").siblings("span").removeClass("curr");
		var type = $(this).data('type');
		$('#bhfxSelect').parent().hide();
		/*
		 * type: 01:病害分类 02:病害处理 03:道路病害 04:桥梁病害 05:隧道病害
		 * */
		 var startTime = JSON.parse(localStorage.getItem("startTime"))
		 var endTime = JSON.parse(localStorage.getItem("endTime"))
		 console.log(startTime)
		 console.log(endTime)
		switch (type) {
			case '01':
				var url = baseUrl + 'dlssxx' + '/main/diseaseanalysis/getdatabyclass';
				$.get(url,{startTime:startTime,endTime:endTime}, function(result) {
					var resObj = JSON.parse(result);
					/*道路、桥梁、隧道 resObj.roads/resObj.bridge/resObj.tunnel*/
					var chartData = {
						title: '病害分类',
						xAxis: resObj.name,
						data: resObj.roads,
						bridge: resObj.bridge,
						tunnel: resObj.tunnel
					};
				createLineChart8(chartData, $('#chart6')[0]);
				});
				$('#chart6').show()
				$('#chart61').hide()
					
				break;
			case '02':
				var url = baseUrl + 'dlssxx' + '/main/diseaseanalysis/getdatabyprocess';
				$.get(url, {startTime:startTime,endTime:endTime},function(result) {
					var resObj = JSON.parse(result);
					var chartData7 = {
						title: '病害处理流程',
						xAxis: resObj.name,
						data: resObj.count
					}
					createBarChart(chartData7, $('#chart61')[0], ['#26ffea', '#b9ff8a'], ['数量']);
				});
				$('#chart61').show()
				$('#chart6').hide()

				// createBarChart(chartData7, $('#chart6')[0], ['#26ffea', '#b9ff8a'], ['数量']);
				break;
			case '03':
				var url1 = baseUrl + 'dlssxx' + '/main/diseaseanalysis/getallroaddiseasecount';
				$('#bhfxSelect').parent().show();
				$.get(url1,{startTime:startTime,endTime:endTime}, function(result) {
					var resObj = JSON.parse(result);
					let names = [];
					let counts = [];
					let firstId = '';
					$("#bhfxSelect option:not(:first)").remove();
					var _op = "";
					$.each(resObj.list,function(index,item){
						if(index == 0){
							firstId = item.fid;
						}
						_op += "<option value='" + item.fid + "'>" + item.froadname +" " + item.count + "</option>"
					});
					$("#bhfxSelect").append(_op);
					layuiSelectRender();
					$.get(baseUrl+'dlssxx' + '/main/diseaseanalysis/getroadsectiondatabyroadid?roadID='+firstId+"&startTime="+ startTime + "&endTime=" +endTime ,function(result2){
						let resObj2 = JSON.parse(result2);
						$.each(resObj2.list,function(index,item){
							names.push(item.roadsectionname);
							counts.push(item.count);
						});
						var chartData = {
							title: '病害分类',
							xAxis: names,
							data: counts
						}
						createBarChart(chartData, $('#chart61')[0], ['#26ffea', '#b9ff8a'], ['数量']);
					});
				});

				$('#chart61').show()
				$('#chart6').hide()

				// var url = baseUrl + 'dlssxx' + '/main/diseaseanalysis/getdatabydamagekind';
				// $.get(url, {
				// 	"kind": "道路"
				// }, function(result) {
				// 	var resObj = JSON.parse(result);
				// 	var chartData = {
				// 		title: '病害分类',
				// 		xAxis: resObj.name,
				// 		data: resObj.count
				// 	}
				// 	createBarChart(chartData, $('#chart6')[0], ['#26ffea', '#b9ff8a'], ['数量']);
				// });

				// createLineChart(chartData8, $('#chart6')[0]);
				break;
			case '04':
				var url = baseUrl + 'dlssxx' + '/main/diseaseanalysis/getdatabydamagekind';
				$.get(url, {
					"kind": '桥梁',
					startTime:startTime,
					endTime:endTime
				}, function(result) {
					var resObj = JSON.parse(result);
					var chartData = {
						title: '病害分类',
						xAxis: resObj.name,
						data: resObj.count
					}
					createBarChart(chartData, $('#chart61')[0], ['#26ffea', '#b9ff8a'], ['数量']);
				});
				$('#chart61').show()
				$('#chart6').hide()


				// createBarChart(chartData7, $('#chart6')[0], ['#26ffea', '#b9ff8a'], ['数量']);
				break;
			case '05':
				var url = baseUrl + 'dlssxx' + '/main/diseaseanalysis/getdatabydamagekind';
				$.get(url, {
					"kind": "隧道",
					startTime:startTime,
					endTime:endTime,
				}, function(result) {
					var resObj = JSON.parse(result);
					var chartData = {
						title: '病害分类',
						xAxis: resObj.name,
						data: resObj.count
					}
					createBarChart(chartData, $('#chart61')[0], ['#26ffea', '#b9ff8a'], ['数量']);
				});
				$('#chart61').show()
				$('#chart6').hide()
				// createBarChart(chartData8, $('#chart6')[0], ['#26ffea', '#b9ff8a'], ['数量']);
				break;
		}
	});
	/*预结算分析 tab 页签*/
	$('#tabWrap1').on('click', 'span', function() {
		$(this).addClass("curr").siblings("span").removeClass("curr");
		var type = $(this).data('type');
		/*
		 * type: 01:道路预结算 02:班组预结算
		 * */
		switch (type) {
			case '01':
				getRoadData();
				// createChart1(chartData1, $('#chart7')[0]);
				// createChart2(chartData2, $('#chart8')[0]);
				break;
			case '02':
				// createChart1(chartData11, $('#chart7')[0]);
				// createChart2(chartData21, $('#chart8')[0]);
				getRoadRepairedData();
				break;
		}
	});
	$('#budgetDate').change(function() {
		getRoadData();
	});

	/*道路预结算，下拉选择道路*/
	$('#budgetRoad').change(function() {
		var rValue = $('#budgetRoad').val();
		if (rValue == '') {
			//默认全部道路
			var chartData21 = {
				title: '全部道路',
				yAxis: ['预算小结', '结算小结'],
				data: [sum(roadResObj.ysCoastList), sum(roadResObj.jsCoastList)]
			};
			createChart2(chartData21, $('#chart8')[0]);
		} else {
			var index = roadResObj.roadList.map(item => item).indexOf(rValue);
			var chartData21 = {
				title: rValue,
				yAxis: ['预算小结', '结算小结'],
				data: [roadResObj.ysCoastList[index], roadResObj.jsCoastList[index]]
			};
			createChart2(chartData21, $('#chart8')[0]);
		}
	});
	/*根据道路，获取预结算数据*/
	function getRoadData() {
		$('#budgetDate').show();
		$('#budgetRoad').show();
		$('#budgetroadrepaired').hide();
		$('#budgetroadrepairedDate').hide();
		var startTime = JSON.parse(localStorage.getItem("startTime"))
		var endTime = JSON.parse(localStorage.getItem("endTime"))
		var data = {
			startTime:startTime,
			endTime:endTime
		};
		// data["dateStr"] = $('#budgetDate').val();
		// console.log($('#budgetDate').val())
		var url = baseUrl + 'measurecheck' + '/main/presettlementanalysis/getroaddatabydatestr';
		$.get(url, data, function(result) {
			roadResObj = JSON.parse(result);
			var tempData = {
				title: '道路预结算',
				xAxis: roadResObj.roadList,
				data: [{
						name: '道理养护结算',
						data: roadResObj.jsCoastList
					},
					{
						name: '道路养护预算',
						data: roadResObj.ysCoastList
					}
				]
			};

			//动态添加班组下拉选择
			var htmlStr = '<option value="">全部道路</option>';
			for (var i = 0; i < roadResObj.roadList.length; i++) {
				htmlStr += '<option value="' + roadResObj.roadList[i] + '">' + roadResObj.roadList[i] + '</option>';
			}
			$('#budgetRoad').empty();
			$('#budgetRoad').append(htmlStr);

			var chartData21 = {
				title: '全部道路',
				yAxis: ['预算小结', '结算小结'],
				data: [sum(roadResObj.ysCoastList), sum(roadResObj.jsCoastList)]
			};
			createChart1(tempData, $('#chart7')[0]);
			createChart2(chartData21, $('#chart8')[0]);
		});
	}


	/*班组预结算，日期变化*/
	$('#budgetroadrepairedDate').change(function() {
		getRoadRepairedData();
	});

	/*下拉选择班组，值发生变化*/
	$('#budgetroadrepaired').change(function() {
		var rValue = $('#budgetroadrepaired').val();
		if (rValue == '') {
			//默认全部班组
			var chartData21 = {
				title: "全部班组",
				yAxis: ['预算小结', '结算小结'],
				data: [sum(repairedResObj.ysCoastList), sum(repairedResObj.jsCoastList)]
			};
			createChart2(chartData21, $('#chart8')[0]);
		} else {
			var index = repairedResObj.nameList.map(item => item).indexOf(rValue);
			var chartData21 = {
				title: rValue,
				yAxis: ['预算小结', '结算小结'],
				data: [repairedResObj.ysCoastList[index], repairedResObj.jsCoastList[index]]
			};
			createChart2(chartData21, $('#chart8')[0]);
		}

	});

	/*根据维修班组，获取预结算数据*/
	function getRoadRepairedData() {
		$('#budgetDate').hide();
		$('#budgetRoad').hide();
		$('#budgetroadrepaired').show();
		$('#budgetroadrepairedDate').show();
		var startTime = JSON.parse(localStorage.getItem("startTime"))
		var endTime = JSON.parse(localStorage.getItem("endTime"))
		var data = {
			startTime:startTime,
			endTime:endTime
		};
		// data["dateStr"] = $('#budgetroadrepairedDate').val();
		var url = baseUrl + 'measurecheck' + '/main/presettlementanalysis/getroadrepairedatabydatestr';
		$.get(url, data, function(result) {
			repairedResObj = JSON.parse(result);
			var tempData = {
				title: '道路预结算',
				xAxis: repairedResObj.nameList,
				data: [{
						name: '道理养护结算',
						data: repairedResObj.jsCoastList
					},
					{
						name: '道路养护预算',
						data: repairedResObj.ysCoastList
					}
				]
			};
			//动态添加班组下拉选择
			var htmlStr = '<option value="">全部班组</option>';
			for (var i = 0; i < repairedResObj.nameList.length; i++) {
				htmlStr += '<option value="' + repairedResObj.nameList[i] + '">' + repairedResObj.nameList[i] + '</option>';
			}
			$('#budgetroadrepaired').empty();
			$('#budgetroadrepaired').append(htmlStr);

			//默认全部班组
			var chartData21 = {
				title: '全部班组',
				yAxis: ['预算小结', '结算小结'],
				data: [sum(repairedResObj.ysCoastList), sum(repairedResObj.jsCoastList)]
			};
			createChart1(tempData, $('#chart7')[0]);
			createChart2(chartData21, $('#chart8')[0]);
		});
	}

	/*数组sum*/
	function sum(arr) {
		var s = 0;
		for (var i = arr.length - 1; i >= 0; i--) {
			s += arr[i];
		}
		return s;
	};
	//加载地图
	createMap();
	//加载道路下拉框并在道路上绘制道路
	// bindRoadSelect();
	//道路设施的统计数据
	countData(null);
	//道路下拉框选择事件（只改变事件）
	// $('#roadSelect').change(function() {
	// 	var roadID = $(this).val();
	// 	countData(roadID);
	// 	var fOverLayears = $('#roadSelect option:selected').attr('id');
	// 	if (fOverLayears == null || fOverLayears == 'null') {
	// 		return;
	// 	}
	// 	map.clearOverlays();
	// 	var data = JSON.parse(fOverLayears);
	// 	commanDrwaing(data, '', 'pointLine', 'orange', 0);
	// })
	/*道路点击事件 */
	$('#roadSection').click(function() {
		var roadID = $('#roadSelect').val();
		if (roadID == null || roadID == '' || roadID == 'all') {
			layui.layer.open({
			  content: '请选择道路'
			});  	
			$(this).removeClass("curr")		
			return;
		} else {
			$.get(baseUrl +'dlssxx/main/daoluldxx/loadroadsections', {
				roadID: roadID
			}, function(data) {
				var selectData = data
				if (!selectData || selectData.length < 0) {
					return
				}
				map.clearOverlays();


				let overLays = [],jsonOverlayears = [];
				for (let j = 0; j < selectData.length; j++) {
					jsonOverlayears = JSON.parse(selectData[j].fOverLayears);
					if (jsonOverlayears == null) continue;
					overLays = overLays.concat(jsonOverlayears);
					commanDrwaing(jsonOverlayears, '', 'pointLine', 'red',1,[selectData[j]]);
				}
				setCenterAndZoom(overLays);
			})
		}
	})
	/*桥梁点击事件 */
	$('#brige').click(function() {
		//清除聚合点
		clearCheckBox();

		var roadID = $('#roadSelect').val();
		if (roadID == null || roadID == '' || roadID == 'all') {
			layui.layer.open({
			  content: '请选择道路'
			}); 
			$(this).removeClass("curr")
			return;
		} else {
			let allPointList = [];
			//画出道路路线
			var fOverLayears = $('#roadSelect').find('option[value="'+selectRoadId+'"]').attr('id');
			if (fOverLayears == null || fOverLayears == 'null') {
				map.clearOverlays();
			}else{
				map.clearOverlays();
				var data = JSON.parse(fOverLayears);
				allPointList = allPointList.concat(data);
				commanDrwaing(data, '', 'pointLine', 'orange', 0);
			}
			$.get(baseUrl +'dlssxx/main/qiaoliang/loadroadallbridges', {
				roadID: roadID
			}, function(data) {
				var selectData = JSON.parse(data);
				var jsonData = [];
				for (var i = 0; i < selectData.length; i++) {
					// jsonData.push({
					// 	lng: selectData[i].fbdlon,
					// 	lat: selectData[i].fbdlat,
					// })
					selectData[i].lng = selectData[i].fbdlon;
					selectData[i].lat = selectData[i].fbdlat;
					// jsonData.push(selectData)
				}
				// map.clearOverlays();
				allPointList = allPointList.concat(selectData);
				setCenterAndZoom(allPointList);
				commanDrwaing(selectData, 'l-q.png', 'point', '', 2);
				// map.addOverlay(marker);

			})
		}
	})
	/*隧道点击事件 */
	$('#tunnl').click(function() {
		//清除聚合点
		clearCheckBox();

		var roadID = $('#roadSelect').val();
		if (roadID == null || roadID == '' || roadID == 'all') {
			layui.layer.open({
			  content: '请选择道路'
			}); 
			$(this).removeClass("curr")
			return;
		} else {
			let allPointList = [];
			//画出道路路线
			var fOverLayears = $('#roadSelect').find('option[value="'+selectRoadId+'"]').attr('id');
			if (fOverLayears == null || fOverLayears == 'null') {
				map.clearOverlays();
			}else{
				map.clearOverlays();
				var data = JSON.parse(fOverLayears);
				allPointList = allPointList.concat(data);
				commanDrwaing(data, '', 'pointLine', 'orange', 0);
			}
			$.get(baseUrl +'dlssxx/main/suidao/loadroadalltunnels', {
				roadID: roadID
			}, function(data) {
				var selectData = JSON.parse(data);
				// var jsonData = [];
				for (var i = 0; i < selectData.length; i++) {
					// jsonData.push({
					// 	lng: selectData[i].fbdlon,
					// 	lat: selectData[i].fbdlat
					// })
					selectData[i].lng = selectData[i].fbdlon;
					selectData[i].lat = selectData[i].fbdlat;
				}
				// map.clearOverlays();
				allPointList = allPointList.concat(selectData);
				setCenterAndZoom(allPointList);
				commanDrwaing(selectData, 'l-s.png', 'point', '', 3);
			})
		}
	})
	/*检查井点击事件 */
	// $('#manhole').click(function() {
	// 	var roadID = $('#roadSelect').val();
	// 	if (roadID == null || roadID == '') {
	// 		alert("请选择道路");
	// 		return;
	// 	} else {
	// 		$.get(baseUrl + 'jcjgl/main/jianzhajgl/loadroadallmanholes', {
	// 			roadID: roadID
	// 		}, function(data) {
	// 			var selectData = JSON.parse(data);
	// 			// var jsonData = [];
	// 			for (var i = 0; i < selectData.length; i++) {
	// 				// jsonData.push({
	// 				// 	lng: selectData[i].BDLON,
	// 				// 	lat: selectData[i].BDLAT
	// 				// })
	// 				selectData[i].lng = selectData[i].fbdlon;
	// 				selectData[i].lat = selectData[i].fbdlat;
	// 			}
	// 			map.clearOverlays();
	// 			commanDrwaing(selectData, 'l-j.png', 'point', '', 4);
	// 		})
	// 	}
	// })
	/*道路附属设施点击事件 */
	$('#other').click(function() {
		//清除聚合点
		clearCheckBox();

		var roadID = $('#roadSelect').val();
		if (roadID == null || roadID == '') {
			alert("请选择道路");
			return;
		} else {
			$.get(baseUrl+'dlssxx/main/daolufsssgl/loadallroadincludeassetbyroadid', {
				roadID: roadID
			}, function(data) {
				var selectData = JSON.parse(data);
				var jsonData = [];
				for (var i = 0; i < selectData.length; i++) {
					// jsonData.push({
					// 	lng: selectData[i].bdlon,
					// 	lat: selectData[i].bdlat,
					// })
					selectData[i].lng = selectData[i].bdlon;
					selectData[i].lat = selectData[i].gpslat;
				}
				// map.clearOverlays();
				setCenterAndZoom(selectData);
				commanDrwaing(selectData, 'l-t.png', 'point', '',5);
			})
		}
	});


	//layui 道路设施 下拉选择框 监听事件
	layui.form.on('select(daoluSelect)', function(data){

		clearCheckBox();
	  	var roadID = data.value;
		countData(roadID);
		selectRoadId = roadID;
		$('.way1').parent().find('.left-list ul>li>a').removeClass('curr');
		$('#roadSelect').find('option[value="'+data.value+'"]').attr('id');
		var fOverLayears = $('#roadSelect').find('option[value="'+data.value+'"]').attr('id');
		if (fOverLayears == null || fOverLayears == 'null') {
			if(data.value === 'all'){
				countData();
				bindRoadFsSelect();
				// map.clearOverlays();
				//清除聚合点
				clearCheckBox();

				let overLays = [];
				for (let j = 0; j < arrdata.length; j++) {
					jsonOverlayears = JSON.parse(arrdata[j].fOverLayears);
					if (jsonOverlayears == null) continue;
					overLays = overLays.concat(jsonOverlayears);
					commanDrwaing(jsonOverlayears, '', 'pointLine', 'orange',0);
				}
				setCenterAndZoom(overLays);
			}else{
				bindRoadFsSelect(data.value,'');
			}
			return;
		}
		bindRoadFsSelect(data.value,'');
		map.clearOverlays();
		var data = JSON.parse(fOverLayears);
		setCenterAndZoom(data);
		commanDrwaing(data, '', 'pointLine', 'orange', 0);
	}); 
	//监听路段选择下拉框
	layui.form.on('select(roadluduan)', function(data){
		let allPointList = [];
		console.log(roadSectionId)
		var roadID = data.value;
		roadSectionId  = roadID
		
		//画出道路路线
		var fOverLayears = $('#roadSelect').find('option[value="'+selectRoadId+'"]').attr('id');
		console.log(fOverLayears)
		console.log(selectRoadId)
		if (fOverLayears == null || fOverLayears == 'null') {
			map.clearOverlays();
	
		}else{
			map.clearOverlays();
			var data = JSON.parse(fOverLayears);
			allPointList = allPointList.concat(data);
			commanDrwaing(data, '', 'pointLine', 'orange', 0);
		}
		var overLays = JSON.parse($("#roadluduan option:checked").attr("id"));
		console.log(overLays)
		var selectData = JSON.parse($("#roadluduan option:checked").attr("name"));
	
		if(!overLays){
			commanDrwaing(allPointList, '', 'pointLine', 'red', 0);
			setCenterAndZoom(allPointList);
			return;
		}
		commanDrwaing(overLays, '', 'pointLine', 'red',1,selectData);
		allPointList = allPointList.concat(selectData);
		setCenterAndZoom(allPointList);
	    bindRoadFsSelect(selectRoadId,roadID);
		
	 });
	//道路设施 附属设施 下拉选择框 监听事件
	layui.form.on('select(fsssSelect)', function(data){
		var roadID = data.value;
		clearCheckBox();
		if(selectRoadId == 'selectRoadId' || selectRoadId == ''){
			layui.layer.open({
				content: '请选择道路'
			});
			$("#roadFsSelect").val('all');
			layuiSelectRender();
			return;
		}
		if(!roadID || !selectRoadId || selectRoadId == 'all'){
			return;
		}
		let allPointList = [];
		//画出道路路线
		var fOverLayears = $('#roadSelect').find('option[value="'+selectRoadId+'"]').attr('id');
		if (fOverLayears == null || fOverLayears == 'null') {
			map.clearOverlays();
		}else{
			map.clearOverlays();
			var data = JSON.parse(fOverLayears);
			allPointList = allPointList.concat(data);
			commanDrwaing(data, '', 'pointLine', 'orange', 0);
		}
		if(roadSectionId) {
			
			var overLays = JSON.parse($("#roadluduan option:checked").attr("id"));
			console.log(overLays)
			var selectData = JSON.parse($("#roadluduan option:checked").attr("name"));
				
			if(!overLays){
				commanDrwaing(allPointList, '', 'pointLine', 'red', 0);
				setCenterAndZoom(allPointList);
				return;
			}
			commanDrwaing(overLays, '', 'pointLine', 'red',1,selectData);
		}
		$.get(baseUrl + 'dlssxx/main/daolufsssgl/loadallroadincludeassetbyroadid?roadID='+selectRoadId+'&assetClassDictID='+roadID + '&roadSectionID='+roadSectionId, {
			warehouseCode: ''
		}, function(data) {

			var selectData = JSON.parse(data);
			for (var i = 0; i < selectData.length; i++) {
				selectData[i].lng = selectData[i].bdlon;
				selectData[i].lat = selectData[i].bdlat;
			}
			allPointList = allPointList.concat(selectData);			
			// map.clearOverlays();
			setCenterAndZoom(allPointList);
			commanDrwaing(selectData, 'imag' + roadID + '.png', 'point', '', 5);
		});
	}); 

	//加载道路下拉框并在道路上绘制道路
	bindRoadSelect();
	//加载所有道路附属设施信息
	bindRoadFsSelect();



	//监听病害分析 选择道路下拉框
	layui.form.on('select(bhfxSelect)', function(data){
		var roadID = data.value;
		if(roadID == 'all'){
			roadID = $("#bhfxSelect option:not(:first)").eq(0).attr('value');
		}
		let names = [],counts = [];
		$.get(baseUrl+'dlssxx' + '/main/diseaseanalysis/getroadsectiondatabyroadid?roadID='+roadID,function(result2){
			let resObj2 = JSON.parse(result2);
			$.each(resObj2.list,function(index,item){
				names.push(item.roadsectionname);
				counts.push(item.count);
			});
			var chartData = {
				title: '病害分类',
				xAxis: names,
				data: counts
			}
			createBarChart(chartData, $('#chart61')[0], ['#26ffea', '#b9ff8a'], ['数量']);
		});
	}); 
	//监测数据 附属设施下拉框
	layui.form.on('select(jcFsssSelect)', function(data){
		var roadID = data.value;
		if(roadID == 'all'){
			roadID = $("#jcFsssSelect option:not(:first)").eq(0);
		}else{
			roadID = $('#jcFsssSelect option[value='+ roadID +']');
		}
		$('#manholeNormal').text(roadID.attr('dcount'));
		$('#manholeWarning').text(roadID.attr('dwarning'));
		$('#manholeOffLine').text(roadID.attr('doffline'));
	});


	

});
/*应急分析*/
// 现将所有的下拉框中的数据绑定上，然后在选择下拉框数据显示分析数据图表
function bindSelect() {
	var startTime = JSON.parse(localStorage.getItem("startTime"))
	var endTime = JSON.parse(localStorage.getItem("endTime"))
	$("#wareHouse option:not(:first)").remove();
	$.get(baseUrl +'yjwzgl/main/emergencyanalysis/getemergencyanalysisdata?startTime='+startTime+"&endTime="+endTime, {
		warehouseCode: '',
		
	}, function(data) {
		var josnData = JSON.parse(data);
		//动态填充选择仓库的下拉框
		var _op = '';

		for (let i = 0; i < josnData.warehouseList.length; i++) {
			var houseItem = josnData.warehouseList[i];
			if (houseItem != null) {
				_op += "<option value='" + houseItem.code + "'>" + houseItem.name + "</option>"
			}

		}
		$("#wareHouse").append(_op);
	});
	//初始化图表
	// createPieChart(chartData6, $('#chart9')[0]);
	// createBarChart(chartData7, $('#chart10')[0], ['#64fa63', '#f3fb4e']);
	createChart12();
}

function createChart12() {
	var startTime = JSON.parse(localStorage.getItem("startTime"))
	var endTime = JSON.parse(localStorage.getItem("endTime"))
	//仓库选择暂时页面没有，有待添加，这里暂时未写死的
	var warehouseCode = $("#wareHouse").val();
	$.get(baseUrl +'yjwzgl/main/emergencyanalysis/getemergencyanalysisdata', {
		warehouseCode: warehouseCode,
		startTime:startTime,
		endTime:endTime
	}, function(data) {
		var josnData = JSON.parse(data);

		// debugger
		/* 应急事件管理 chart6*/
		var yjdata = [{
			name: '已发现',
			value: 0
		}, {
			name: '已制定方案',
			value: 0
		}
		,
		{
			name:'已抢险完成',
			value:0
		}
		];
		for (let i = 0; i < josnData.eventStatusList.length; i++) {
			var item = josnData.eventStatusList[i];
			for (let j = 0; j < yjdata.length; j++) {
				var yjitem = yjdata[j];
				if (item.eventstatus == yjitem.name) {
					yjitem.value = item.count;
					break;
				}
			}
		}

		var tempDatas = {
			title: '应急事件管理',
			data: yjdata
		};
		createPieChart(tempDatas, $('#chart9')[0]);
		/* 物资库存管理 chart7*/
		var x_index = ['已申请入库', '已审批入库', '待入库', '库存', '申请出库', '已审批出库', '已出库'];
		var wzdata = [0, 0, 0, 0, 0, 0, 0];
		for (let n = 0; n < josnData.materialStockList.length; n++) {
		 var josnItem = josnData.materialStockList[n];
		 for (m = 0; m < x_index.length; m++) {
		  if (josnItem.status == x_index[m]) {
		   wzdata[m] = josnItem.count;
		  }
		 }
		}
		var chartwzData = {
			title: '物资库存管理',
			xAxis: x_index,
			data: wzdata
		};

		createBarChart(chartwzData, $('#chart10')[0], ['#64fa63', '#f3fb4e']);
	})
};

/* 请求所有道路信息,并加载到下拉框中 */
function bindRoadSelect() {
	$("#roadSelect option:not(:first)").remove();
	$.get(baseUrl +'dlssxx/main/daoluxx/loadallroads', function(data) {
		console.log($('#roadSelect'));
		var _op = "<option value=''>请选择道路</option>";
		for (let i = 0; i < data.length; i++) {
			_op += "<option value='" + data[i].fid + "' id='" + data[i].fOverLayears + "'>" + data[i].fRoadName + "</option>"
		}
		$("#roadSelect").append(_op);
		layuiSelectRender();
		arrdata = data;
		let overLays = [];
		for (let j = 0; j < data.length; j++) {
			jsonOverlayears = JSON.parse(data[j].fOverLayears);
			if (jsonOverlayears == null) continue;
			overLays = overLays.concat(jsonOverlayears);
			commanDrwaing(jsonOverlayears, '', 'pointLine', 'orange',0);
		}
		setCenterAndZoom(overLays);
	});
};
// 查询附属设施信息 列表，下拉框数据  param roadId  
function bindRoadFsSelect(roadId, roadSectionId){

	$("#roadFsSelect option:not(:first)").remove();
	let url = baseUrl +'dlssxx/main/daoluxx/roadassetaccount';
	if(roadId&& roadSectionId == ''){
		url += '?roadID='+roadId 
	
		
	}
	if(roadSectionId) {
		url += '?roadID='+roadId + '&roadSectionID=' + roadSectionId
	}
	$.get(url, function(res) {
		let data = JSON.parse(res);
		var _op = "<option value=''>请选择附属设施</option>";
		for (let i = 0; i < data.roadIncludeAssets.length; i++) {
			_op += '<option value="'+ data.roadIncludeAssets[i].fAssetClassDictId +'" num="'+ data.roadIncludeAssets[i].count +'">'+ data.roadIncludeAssets[i].fClassName +'</option>';
		}
		$("#roadFsSelect").append(_op);
		layuiSelectRender();
	});
}

//添加附属设施 下拉列表 图标
function layuiSelectRender(){
	layui.form.render("select");
	let timeSelect = setTimeout(
		function(){
			let isInit = 0;
			if($('#jcFsssSelect').parent().find('.layui-form-select dd')){
				++isInit;
				$('#jcFsssSelect').parent().find('.layui-form-select dd').each(function(){
					$(this).find('span').remove();
					let vId = $(this).attr('lay-value');
					let valueDom =  $('#jcFsssSelect').find('option[value="'+vId+'"]');
					let num =valueDom.attr('dcount'),id = valueDom.attr('value');
					if(!id || id == 'all'){
						return;
					}
					$(this).attr('style','font-size:15px;');
					$(this).append('<span style="color: #06FBF6;margin-left:10px;">'+ num +'</span>');
				});
			}
			if($('#roadFsSelect').parent().find('.layui-form-select dd')){
				++isInit;
				$('#roadFsSelect').parent().find('.layui-form-select dd').each(function(){
					$(this).find('span').remove();
					$(this).find('img').remove();
					let vId = $(this).attr('lay-value');
					let valueDom =  $('#roadFsSelect').find('option[value="'+vId+'"]');
					let num =valueDom.attr('num'),id = valueDom.attr('value');
					if(!id || id == 'all'){
						return;
					}
					$(this).attr('style','font-size:15px;');
					$(this).append('<span style="color: #06FBF6;margin-left:10px;">'+ num +'</span>');
					$(this).prepend('<img src="./img/imag'+ id +'.png" style="height:24px;width:24px;margin-right:8px;" />');
				});
			}
			if(isInit === 2){
				clearTimeout(timeSelect);
			}else{
				timeSelect();
			}
		},10
	);
}

//设置缩放级别
function setCenterAndZoom(points){
	// console.log(points);
	baiDuSetZoom(points);
}


//1.根据原始数据计算中心坐标和缩放级别，并为地图设置中心坐标和缩放级别。  
function baiDuSetZoom(points){  
    if(points.length>0){  
        var maxLng = points[0].lng;  
        var minLng = points[0].lng;  
        var maxLat = points[0].lat;  
        var minLat = points[0].lat;  
        var res;  
        for (var i = points.length - 1; i >= 0; i--) {  
            res = points[i];  
            if(res.lng > maxLng) maxLng =res.lng;  
            if(res.lng < minLng) minLng =res.lng;  
            if(res.lat > maxLat) maxLat =res.lat;  
            if(res.lat < minLat) minLat =res.lat;  
        };  
        var cenLng =(parseFloat(maxLng)+parseFloat(minLng))/2;  
        var cenLat = (parseFloat(maxLat)+parseFloat(minLat))/2;  
        var zoom = baiDuGetZoom(maxLng, minLng, maxLat, minLat);  
        map.centerAndZoom(new BMap.Point(cenLng,cenLat), zoom);    
    }else{  
        //没有坐标，显示全中国  
        // map.centerAndZoom(new BMap.Point(103.388611,35.563611), 5);    
    }   
}  
//===================================================
//  2.计算缩放级别的函数
function baiDuGetZoom (maxLng, minLng, maxLat, minLat) {
     var zoom = ["50","100","200","500","1000","2000","5000","10000","20000","25000","50000","100000","200000","500000","1000000","2000000"]//级别18到3。  
     //最大最小的坐标点
    var pointA = new BMap.Point(maxLng,maxLat);  // 创建点坐标A  
    var pointB = new BMap.Point(minLng,minLat);  // 创建点坐标B  
    var distance = map.getDistance(pointA,pointB).toFixed(1);  //获取两点距离,保留小数点后两位 
    for(var i=0,zoomLen = zoom.length; i <zoomLen; i++) {
        if(zoom[i] - distance > 0) {
            return 18 -i + 3; 
            //地图范围常常是比例尺距离的10倍以上 所以加3
        }
    };
}

/**
 * 路段信息
 */
function selectLuduan(obj){
console.log('路段信息'+obj);
	var roadID = obj;
	// if (roadID == null || roadID == '' || roadID == 'all') {
	// 	layui.layer.open({
	// 		content: '请选择道路'
	// 	});
	// 	$(this).removeClass("curr")
	// 	return;
	// } else {
	// 	$.get(baseUrl +'dlssxx/main/daoluldxx/loadroadsections', {
	// 		roadID: roadID
	// 	}, function(data) {
	// 		//追加道路信息
	// 		var _op = "<option value='all'>请选择路段</option>";
	// 		for (let i = 0; i < data.length; i++) {
	// 			_op += "<option name ='"+JSON.stringify(data[i])+"' value='" + data[i].fid + "' id='" + data[i].fOverLayears + "'>" + data[i].fRoadSectionName + "</option>"
	// 		}
	// 		$("#roadluduan").empty();
	// 		$("#roadluduan").append(_op);
	// 		layuiSelectRender();
	//
	// 	})
	// }

	$.get(baseUrl +'dlssxx/main/daoluldxx/loadroadsections', {
		roadID: roadID
	}, function(data) {
		//追加道路信息
		var _op = "<option value=''>请选择路段</option>";
		for (let i = 0; i < data.length; i++) {
			_op += "<option name ='"+JSON.stringify(data[i])+"' value='" + data[i].fid + "' id='" + data[i].fOverLayears + "'>" + data[i].fRoadSectionName + "</option>"
		}
		$("#roadluduan").empty();
		$("#roadluduan").append(_op);
		layuiSelectRender();

	})
}






/* 
data:地图加载数据为点的数组,
img:打点图片,
type:point 点,pointLine:线 */
function commanDrwaing(data, img, type, setColor, ywtype,selectData) {
	
	var pointarr = [];
	for (let n = 0; n < data.length; n++) {
		var point = new BMap.Point(data[n].lng, data[n].lat, );
		pointarr.push(point);
	}
	// map.centerAndZoom(pointarr[0], 15);
	if (pointarr.length > 0) {
		if (type == 'pointLine') {
			if(ywtype == 0) {
				var polyline = new BMap.Polyline(pointarr, {
					strokeColor: setColor,
					strokeWeight: 5,
					strokeOpacity: 1,
				});
				map.addOverlay(polyline); //将画出的线展示在地图上
			}else if(ywtype == 1) {
				var polyline = new BMap.Polyline(pointarr, {
					strokeColor: setColor,
					strokeWeight: 5,
					strokeOpacity: 1,
				});
				map.addOverlay(polyline); 
				polyline.addEventListener("click", function (e) {
					console.log(selectData)
					//console.log(selectData[0].fLocationName)
				//	$('')
					//var dataJson = selectData[0];
					var dataJson = selectData;

					$('.pointDisNCz') && $('.pointDisNCz').remove();
					$('.disNCz').find('.yad-list') && $('.disNCz').find('.yad-list').remove();
					var htmlStr =    
									'<div class="yad-list lu"><i id="gbclod"><img src="img/icon.png" alt="" /></i>' +
									'<table class="table" style="margin-bottom: 0;">' +
									'<tr><th>道路名称</th><td>'+ (dataJson.fLocationName || '--') + '</td><th>道路等级</th><td>' + dataJson.fRoadGradeName +
									'</td></tr>' +
									'<tr><th>路段编码</th><td>' + ((typeof(dataJson.fRoadSectionCode) !== 'undefined' && dataJson.fRoadSectionCode) ? dataJson.fRoadSectionCode :
										'--') + '</td><th>路段名称</th><td>' + ((typeof(dataJson.fRoadSectionName) !== 'undefined' && dataJson.fRoadSectionName) ? dataJson.fRoadSectionName : '') +
									'</td></tr>' +
									'<tr><th>起点名称</th><td>' + ((typeof(dataJson.fRoadSectionEnd) !== 'undefined' && dataJson.fRoadSectionEnd) ? dataJson.fRoadSectionEnd :
										'--') + '</td><th>止点名称</th><td>' + ((typeof(dataJson.fRoadSectionEnd) !== 'undefined'&&  dataJson.fRoadSectionEnd) ? dataJson.fRoadSectionEnd :
										'--') + '</td></tr>' +
									'<tr><th>起点桩号</th><td>' + ((typeof(dataJson.fPileNumberStart) !== 'undefined' && dataJson.fPileNumberStart) ? dataJson.fPileNumberStart : '--') +
									'</td><th>止点桩号</th><td>' +((typeof(dataJson.fPileNumberEnd) !== 'undefined' && dataJson.fPileNumberEnd)? dataJson.fPileNumberEnd : '--') +
									'</td></tr>' +
									'<tr><th>主路长</th><td>' + ((typeof(dataJson.fSectionLenth) !== 'undefined' && dataJson.fSectionLenth) ? dataJson.fSectionLenth : '--') +
									'米</td><th>主路宽</th><td>' + ((typeof(dataJson.fSectionWide) !== 'undefined' && dataJson.fSectionWide) ? dataJson.fSectionWide : '--') +
									'米</td></tr>' +
									'<tr><th>主路面积</th><td>' + ((typeof(dataJson.fSectionArea) !== 'undefined' && dataJson.fSectionArea) ? dataJson.fSectionArea :
										'--') +
									'</td><th>所属区域</th><td>'+ ((typeof(dataJson.fLocationName) !== 'undefined'&& dataJson.fLocationName) ? dataJson.fLocationName :
										'--')+'</td></tr>' + 
									'<tr><th>路面等级</th><td>' + ((typeof(dataJson.fPavementGradeName) !== 'undefined' && dataJson.fPavementGradeName) ? dataJson.fPavementGradeName :
										'--') + '</td><th>路面类型</th><td>' + ((typeof(dataJson.fPavementTypeName) !== 'undefined' && dataJson.fPavementTypeName) ? dataJson.fPavementTypeName :
										'--') +
									'</td></tr>' +
									'<tr><th>养护单位</th><td>' + ((typeof(dataJson.fMaintainofficeName) !== 'undefined' && dataJson.fMaintainofficeName) ? dataJson.fMaintainofficeName :
										'--') + '</td><th>巡查单位</th><td>' + ((typeof(dataJson.fPatrolofficeName) !== 'undefined' && dataJson.fPatrolofficeName) ? dataJson.fPatrolofficeName :
										'--') +
									'</td></tr>' +
									'</table></div></div>'
									$('.disNCz').append(htmlStr);
									$('.disNCz').show();
									$('#gbclod').click(function() {
										$('.lu').remove();
										$('.disNCz').hide();
									})
				});
			}
		} else if (type == 'point') {
			for (var i = 0; i < pointarr.length; i++) {
				var myIcon = new BMap.Icon("img/" + img + "", new BMap.Size(30, 30));
				var pt = pointarr[i];
				var marker = new BMap.Marker(pt, {
					icon: myIcon
				}); // 创建标注
				marker.datas = data[i];
				marker.addEventListener("click", function(e) {
					// console.log(e.target.datas)
					let dataJson = e.target.datas
					console.log(e.target.Ac)
					console.log($(e.target.Ac).find('.pointDisNCz'))
					$('.disNCz').find('.yad-list') && $('.disNCz').find('.yad-list').remove();
					$('.disNCz').hide();
					if ($(e.target.Ac).find('.pointDisNCz') && $(e.target.Ac).find('.pointDisNCz').css('display') =='block') {
						$(e.target.Ac).find('.pointDisNCz').remove();
						console.log('12')
					} else {
						$(e.target.Ac).find('.pointDisNCz') && $(e.target.Ac).find('.pointDisNCz').remove();
						if (ywtype == 2) {
							var htmlStr =
								'<div class="pointDisNCz" style="position:absolute;padding:10px; left: -160px; width:688px; bottom:20px;z-index: 9999;background-color:#1D2127; border: 1px solid #0eb1fd;color:#fff; font-size:16px">' +
								'<div class="yad-list"><i id="pointGbclod"><img src="img/icon.png" alt="" /></i>' +
								'<table class="table" style="margin-bottom: 0;">' +
								'<tr><th>桥梁编码</th><td>' + dataJson.fbridgecode + '</td><th>桥梁名称</th><td>' + dataJson.fbridgename +
								'</td></tr>' +
								'<tr><th>道路路段</th><td>' + ((typeof(dataJson.roadsectionname) !== 'undefined') ? dataJson.roadsectionname :
									'--') + '</td><th>所属区域</th><td>' + ((typeof(dataJson.flocation) !== 'undefined') ? dataJson.flocation : '') +
								'</td></tr>' +
								'<tr><th>养护单位</th><td>' + ((typeof(dataJson.maintainOfficeName) !== 'undefined') ? dataJson.maintainOfficeName :
									'--') + '</td><th>巡查单位</th><td>' + ((typeof(dataJson.patrolofficeName) !== 'undefined') ? dataJson.patrolofficeName :
									'--') + '</td></tr>' +
								'<tr><th>桥梁类型</th><td>' + (typeof(dataJson.bridgeTypeName) !== 'undefined' ? dataJson.bridgeTypeName : '--') +
								'</td><th>建成通车日</th><td>' + ((dataJson.fopentrafficday !== 'undefined') ? dateFormat('YYYY-mm-dd',new Date(dataJson.fopentrafficday)) : '--') +
								'</td></tr>' +
								'<tr><th>桥梁全长</th><td>' + ((typeof(dataJson.fbridgelenth) !== 'undefined') ? dataJson.fbridgelenth : '--') +
								'米</td><th>桥梁全宽</th><td>' + ((typeof(dataJson.fbridgewide) !== 'undefined') ? dataJson.fbridgewide : '--') +
								'米</td></tr>' +
								'<tr><th>桥面净宽</th><td>' + ((typeof(dataJson.fbridgeclearwide) !== 'undefined') ? dataJson.fbridgeclearwide :
									'--') +
								'</td><th>跨径分类</th><td></td></tr>' + ((typeof(dataJson.spanClassName) !== 'undefined') ? dataJson.spanClassName :
									'--') +
								'<tr><th>主桥结构</th><td>' + ((typeof(dataJson.bridgeStructureName) !== 'undefined') ? dataJson.bridgeStructureName :
									'--') + '</td><th>设计荷载</th><td>' + ((typeof(dataJson.bridgeLoadName) !== 'undefined') ? dataJson.bridgeLoadName :
									'--') +
								'</td></tr>' +
								'<tr><th>桥墩类型</th><td>' + ((typeof(dataJson.pieTypeName) !== 'undefined') ? dataJson.pieTypeName :
									'--') + '</td><th>抗震等级</th><td>' + ((typeof(dataJson.antiseismicGrideName) !== 'undefined') ? dataJson.antiseismicGrideName :
									'--') +
								'</td></tr>' +
								'</table></div></div>'
						} else if (ywtype == 3) {
							var htmlStr =
								'<div class="pointDisNCz" style="position:absolute;padding:10px; left: -160px; width:688px; bottom:20px;z-index: 9999;background-color:#1D2127; border: 1px solid #0eb1fd;color:#fff; font-size:16px">' +
								'<div class="yad-list"><i id="pointGbclod"><img src="img/icon.png" alt="" /></i>' +
								'<table class="table" style="margin-bottom: 0;">' +
								'<tr><th>隧道编码</th><td>' + dataJson.ftunnelcode + '</td><th>隧道名称</th><td>' + dataJson.fbridgename +
								'</td></tr>' +
								'<tr><th>道路路段</th><td>' + ((typeof(dataJson.roadsectionname) !== 'undefined') ? dataJson.roadsectionname :
									'--') + '</td><th>所属区域</th><td>' + ((typeof(dataJson.flocation) !== 'undefined') ? dataJson.flocation : '') +
								'</td></tr>' +
								'<tr><th>养护单位</th><td>' + ((typeof(dataJson.maintainofficeName) !== 'undefined') ? dataJson.maintainofficeName :
									'--') + '</td><th>巡查单位</th><td>' + ((typeof(dataJson.patrolofficeName) !== 'undefined') ? dataJson.patrolofficeName :
									'--') + '</td></tr>' +
								'<tr><th>隧道类型</th><td>' + (typeof(dataJson.tunnelClassName) !== 'undefined' ? dataJson.tunnelClassName : '--') +
								'</td><th>建成通车日</th><td>' + ((dataJson.fopentrafficday !== 'undefined') ? dateFormat('YYYY-mm-dd',new Date(dataJson.fopentrafficday)) : '--') +
								'</td></tr>' +
								'<tr><th>隧道长度</th><td>' + ((typeof(dataJson.ftunnellenth) !== 'undefined') ? dataJson.ftunnellenth : '--') +
								'米</td><th>隧道净宽</th><td>' + ((typeof(dataJson.ftunnelwide) !== 'undefined') ? dataJson.ftunnelwide : '--') +
								'米</td></tr>' +
								'<tr><th>隧道净高</th><td>' + ((typeof(dataJson.ftunnelhight) !== 'undefined') ? dataJson.ftunnelhight : '--') +
								'米</td><th>人行道宽</th><td>' + ((typeof(dataJson.ffootwaikwide) !== 'undefined') ? dataJson.ffootwaikwide : '--') +
								'米</td></tr>' +
								'<tr><th>洞口形式</th><td>' + ((typeof(dataJson.potalFormName) !== 'undefined') ? dataJson.potalFormName :
									'--') + '</td><th>断面形式</th><td>' + ((typeof(dataJson.sectionFormName) !== 'undefined') ? dataJson.sectionFormName :
									'--') +
								'</td></tr>' +
								'<tr><th>隧道排水类型</th><td>' + ((typeof(dataJson.drainageTypeName) !== 'undefined') ? dataJson.drainageTypeName :
									'--') + '</td><th>安全通道数量</th><td>' + ((typeof(dataJson.fsecurechannelnumber) !== 'undefined') ? dataJson.fsecurechannelnumber :
									'--') +
								'</td></tr>' +
								'</table></div></div>'
						}
						if(ywtype == 4) {
							var htmlStr =
								'<div class="pointDisNCz" style="position:absolute;padding:10px; left: -160px; width:688px; bottom:20px;z-index: 9999;background-color:#1D2127; border: 1px solid #0eb1fd;color:#fff; font-size:16px">' +
								'<div class="yad-list"><i id="pointGbclod"><img src="img/icon.png" alt="" /></i>' +
								'<table class="table" style="margin-bottom: 0;">' +
								'<tr><th>检查井编码</th><td>' + dataJson.ManholeCode + '</td><th>检查井分类</th><td>' + dataJson.ManholeType +
								'</td></tr>' +
								'<tr><th>道路路段</th><td>' + ((typeof(dataJson.RoadSectionName) !== 'undefined') ? dataJson.RoadSectionName :
									'--') + '</td><th>井盖形状</th><td>' + ((typeof(dataJson.ShapeName) !== 'undefined') ? dataJson.ShapeName : '') +
								'</td></tr>' +
								'<tr><th>所在位置</th><td>' + ((typeof(dataJson.ManholePos) !== 'undefined') ? dataJson.ManholePos :
									'--') + '</td><th>井盖规格</th><td>' + ((typeof(dataJson.ShapeSize) !== 'undefined') ? dataJson.ShapeSize :
									'--') + '</td></tr>' +
								'<tr><th>井盖材质</th><td>' + (typeof(dataJson.MaterialName) !== 'undefined' ? dataJson.MaterialName : '--') +
								'</td><th>权属单位</th><td>' + ((dataJson.OwnershipOfficeName !== 'undefined') ? dataJson.OwnershipOfficeName : '--') +
								'</td></tr>' +
								// '<tr><th>隧道长度</th><td>' + ((typeof(dataJson.ftunnellenth) !== 'undefined') ? dataJson.ftunnellenth : '--') +
								// '米</td><th>隧道净宽</th><td>' + ((typeof(dataJson.ftunnelwide) !== 'undefined') ? dataJson.ftunnelwide : '--') +
								// '米</td></tr>' +
								// '<tr><th>隧道净高</th><td>' + ((typeof(dataJson.ftunnelhight) !== 'undefined') ? dataJson.ftunnelhight : '--') +
								// '米</td><th>人行道宽</th><td>' + ((typeof(dataJson.ffootwaikwide) !== 'undefined') ? dataJson.ffootwaikwide : '--') +
								// '米</td></tr>' +
								// '<tr><th>洞口形式</th><td>' + ((typeof(dataJson.potalFormName) !== 'undefined') ? dataJson.potalFormName :
								// 	'--') + '</td><th>断面形式</th><td>' + ((typeof(dataJson.sectionFormName) !== 'undefined') ? dataJson.sectionFormName :
								// 	'--') +
								// '</td></tr>' +
								// '<tr><th>隧道排水类型</th><td>' + ((typeof(dataJson.drainageTypeName) !== 'undefined') ? dataJson.drainageTypeName :
								// 	'--') + '</td><th>安全通道数量</th><td>' + ((typeof(dataJson.fsecurechannelnumber) !== 'undefined') ? dataJson.fsecurechannelnumber :
								// 	'--') +
								// '</td></tr>' +
								'</table></div></div>'
						}
						//附属设施点击
						if(ywtype == 5) {
							console.log(dataJson + '=====datajson')
							var htmlStr=
							'<div class="pointDisNCz" style="position:absolute;padding:10px; left: -160px; width:688px; bottom:20px;z-index: 9999;background-color:#1D2127; border: 1px solid #0eb1fd;color:#fff; font-size:16px">' +
							'<div class="yad-list"><i id="pointGbclod"><img src="img/icon.png" alt="" /></i>' +
							'<table class="table" style="margin-bottom: 0;">' +
							'<tr><th>设施编码</th><td>' + dataJson.assetcode + '</td><th>设施类型</th><td>' + dataJson.fClassName +
							'</td></tr>' +
							'<tr><th>道路路段</th><td>' + ((typeof(dataJson.roadsectionname) !== 'undefined') ? dataJson.roadsectionname :
								'--') + '</td><th>形状</th><td>' + (dataJson.shapeid != 'NULL'&&'undefined' ? dataJson.shapeid :
								'--')+
							'</td></tr>' +
							'<tr><th>所在位置</th><td>' + ((typeof(dataJson.assetpos) !== 'undefined') ? dataJson.assetpos :
								'--') + '</td><th>规格</th><td>' + ((typeof(dataJson.shapesize) !== 'undefined') ? dataJson.shapesize :
								'--') + '</td></tr>' +
							'<tr><th>材质</th><td>' + (typeof(dataJson.materialid) !== 'undefined' ? dataJson.materialid : '--') +
							'</td><th>权属单位</th><td>' + ((dataJson.ownershipOfficeName !== 'undefined') ? dataJson.ownershipOfficeName : '--') +
							'</td></tr>' +
							'</table></div></div>'
							
						}
						$(e.target.Ac).append(htmlStr);
						$(e.target.Ac).find('#pointGbclod').click(function() {
							$(e.target.Ac).find('.pointDisNCz').remove();
						})

					}
					// var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;width: 500px; height: 100px;'>详细信息</p>");  
					// this.openInfoWindow(infoWindow); 
				});

				map.addOverlay(marker); // 将标注添加到地图中

			}
		}

	}
};

/* 传入道路ID,统计该条道路下所有的数据,如果没有传入则查全部道路的 */
function countData(roadID, roadSectionId) {
	if (roadID == null) {
		$.get(baseUrl +'dlssxx/main/daoluxx/roadassetaccount', function(data) {
			var jsondata = JSON.parse(data);
			//$('#roadSection').find('strong').html(jsondata.roadSectionNum);
			$('#brige').find('strong').html(jsondata.bridgeNum);
			$('#tunnl').find('strong').html(jsondata.tunnelNum);
			$('#manhole').find('strong').html(jsondata.manholeNum);
			$('#other').find('strong').html(jsondata.otherNum);

			selectLuduan(roadID,roadSectionId);//路段
		})
	} else {
		$.get(baseUrl +'dlssxx/main/daoluxx/roadassetaccount', {
			roadID: roadID,
			roadSectionID: roadSectionId
		}, function(data) {
			var jsondata1 = JSON.parse(data);
			//$('#roadSection').find('strong').html(jsondata1.roadSectionNum);
			$('#brige').find('strong').html(jsondata1.bridgeNum);
			$('#tunnl').find('strong').html(jsondata1.tunnelNum);
			$('#manhole').find('strong').html(jsondata1.manholeNum);
			$('#other').find('strong').html(jsondata1.otherNum);

			selectLuduan(roadID,roadSectionId);//路段

		})
	}
}
Date.prototype.Format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"H+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[
			k]).substr(("" + o[k]).length)));
	return fmt;
};
function dateFormat(fmt, date) {
    let ret;
    const opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}